<template>
	<view class="box">
		<uNavbar title="商城订单" ></uNavbar>
		<view class="tab-nav">
			<view class="tab-list-item" v-for="(item,index) in toggleList" :key="item.id"
				@click="clickToggleHandle(item,index)">
				<view :class="{ active: indexs==index}" class="text">{{ item.label }}</view>
			</view>
		</view>
		<!--我接收的 -->
		<view style="margin-top: 100rpx;">
			<view class="main_from"  v-for="item in orderlist" :key="item.id">
				<view class="main_from_top" v-for="(itm,idx) in item.shop_order_goods" :key="idx" @click="godetail2(item.id)">
					<image :src="itm.spec_thumb" mode="aspectFill"></image>
					<view class="main_from_top_one">
						<view class="name">
							{{itm.goods_name}}
						</view>
						<view class="time">
							{{item.status_desc}}
						</view>
					</view>
					<view class="main_from_top_two">
						<view class="text">
							
						</view>
						<view class="num">
							×{{itm.nums}}
						</view>
					</view>
					<view class="main_from_top_three">
						<view class="price">
							<image class="money1" v-if="item.pay_type==3" src="../../static/icon/fhtb.png" mode=""></image>
							<image class="money2" v-if="item.pay_type==4" src="../../static/image/fhyb.png" mode=""></image>
							<image class="money3" v-if="item.pay_type==5" src="/static/icon/i_ful.png" mode=""></image>
							<image class="money3" v-if="item.pay_type==7" src="../../static/icon/i_integral.png" mode=""></image>
							<text v-if="item.pay_type==8 ||item.pay_type==9">￥</text>
							{{item.pay_price}}
						</view>	
					</view>
					<view v-if="item.status==2"  class="tipps">
							{{item.express_data?item.express_data[0].AcceptStation:"暂无物流信息"}}
					</view>
				</view>
				<view class="main_from_bottom" >
					<view class="main_from_bottom_text" @click="godetail2(item.id)">
						查看详情
					</view>
					<view class="btn_canel" v-show="item.status==1&&item.order_type!=3&&item.order_type!=6&&item.order_type!=5&&item.order_type!=7&&item.order_type!=8" @click="itemid=item.id,tipShow=true">
						取消订单
					</view>
					<view class="btn_canel" v-show="item.status==2" @click="itemid=item.id,tipShow2=true">
						确认收货
					</view>
					<view class="btn_canel_s" v-show="item.status==-1" >
						已取消
					</view>
					<!-- 		<view class="btn_canel" v-show="item.status==1">
						转赠
					</view> -->
		<!-- 			<view class="btn" v-show="item.status==0" @click="gounpaid(item.id,item.countDown)">
						去付款
					</view> -->
					<!-- 		<view class="btn" v-show="item.status==1" >
						挂卖
					</view> -->
				</view>
			</view>
		</view>
		<u-popup :show="tipShow" mode="center" @close="tipShow = false" closeable bgColor="transparent">
			<view class="prompt flex_ZC">
				<text class="f36">提示</text>
				<text class="prompt_tit">确定要取消订单吗</text>
				<view class="prompt_ntm" @click="canel1()">
					<text>确定</text>
				</view>
				<view class="empty"></view>
			</view>
		</u-popup>
		<u-popup :show="tipShow2" mode="center" @close="tipShow2 = false" closeable bgColor="transparent">
			<view class="prompt flex_ZC">
				<!-- <text class="f36">提示</text> -->
				<text class="prompt_tit">确定要收货吗</text>
				<text class="c6 tipp" >{{buy_shop_order}}</text>
				<view class="prompt_ntm" @click="sub()">
					<text>确定</text>
				</view>
				<view class="empty"></view>
			</view>
		</u-popup>
		<noDatas  :xxxList="orderlist" :status="status"></noDatas>
	</view>

</template>

<script>

	import {orderList,orderCancel,orderConfirm,config} from "../../api/shopp.js"
	export default {
		data() {
			return {
				toggleList: [
					{
						label: '全部',
						// select: true
					}, 
					{
						label: '待发货',
						// select: false
					},
					{
						label: '待收货',
						// select: false
					},
					{
						label: '已完成',
						// select: false
					}

				],
				selval: "我的挂单",
				status: "已购买",
				status2: "未购买",
				orderlist: [],
				orderlist2: [],
				page: 1,
				size: 20,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				
				tipShow: false,
				tipShow2: false,
				itemid: "",
				indexs: 0,
				selnum:0,
				showrule:false,
				buy_shop_order:""
			}
		},
		onLoad(options) {
		this.gettip()
		},
		onShow() {
			this.getlist()
		},
		methods: {
			gettip(){
				config().then(res=>{
					this.buy_shop_order=res.data.buy_shop_order
				})
			},
			sub(){
				orderConfirm({
					order_id: this.itemid
					
				}).then(res=>{
					if (res.code == 1) {
						this.tipShow2 = false
						this.page=1
						this.getlist()
					}
					uni.$u.toast(res.msg)
				})
			},
			canel1() {
				orderCancel({
					order_id: this.itemid
				}).then(res => {
					if (res.code == 1) {
						this.tipShow = false
						this.page=1
						this.getlist()
					}
					uni.$u.toast(res.msg)
				})
			},
			getlist() {
				orderList({
					status:this.selnum,
					page: this.page
				}).then(res => {
					if (res.code == 1) {
						let list = res.data.data;
						this.orderlist = this.page == 1 ? list : this.orderlist.concat(list);
						console.log(this.orderlist);
						if (list.length < this.size) this.status = 'nomore';
						else this.status = 'loading';
					}
				})
			},

			clickToggleHandle(ele, index) {
				this.indexs = index
				this.selnum=index
				this.toggleList.forEach(item => item.select = false)
				this.currLabel = ele.label
				ele.select = true
				console.log(ele)
				this.selval = ele.label
				this.page=1
				this.orderlist=[]
				this.getlist()
			},
			gounpaid(id) {
				uni.navigateTo({
					url: `/pagesMy/brandCenter/paymentCenter?productType=3&order_id=${id}`
				})
			},
			godetail(id, status) {
				console.log(status)
				// if (status == 1 ) {
					uni.navigateTo({
						url: `/pagesMy/proporder/proporderdetail?id=${id}&status=${status}`
					})
				// }

			},
			godetail2(id) {
				
				// if (status == 2) {
					uni.navigateTo({
						
						url: `/pagesMy/shoppingCenter/shoporderdetail?id=${id}`
					})
				// }
			},
			gopaid() {
				if (this.selval == "已购买") {
					uni.navigateTo({
						url: "/pagesMy/myorder/paid"
					})
				} else {
					uni.navigateTo({
						url: "/pagesMy/myorder/unpaid"
					})
				}

			}

		},
		onReachBottom() {
		
				if (this.status != 'nomore') {
					this.page = this.page + 1
					this.getlist()
				}
			

		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 750rpx;
		// height: 100vh;
		background-color: #E0DDDA;
		position: relative;
		// overflow: auto;
	}
	.tipp{
		width: 480rpx;
		height: 64rpx;
		margin: 0 auto;
		text-align: center;
		font-weight: 400;
		font-size: 28rpx;
		color: #999999;
	}
	.tipps{
		width: 630rpx;
		height: 64rpx;
		margin-top: 10rpx;
		background: #E9E7E6;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #999999;
		line-height: 64rpx;
		white-space: nowrap;
		/* 不换行 */
		overflow: hidden;
		/* 超出部分隐藏 */
		text-overflow: ellipsis;
		text-indent: 20rpx;
	}
	.tab-nav {
		width: 750rpx;
		height: 100rpx;
		background-color: #E0DDDA;
		// margin-left: 20rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		position: fixed;
		z-index: 999;

		.tab-list-item {
			position: relative;
			// width: 350rpx;

			.text {
				display: flex;
				justify-content: center;
				align-items: center;
				// margin-left: 50rpx;
				// padding: 20rpx;
				height: 52rpx;
				opacity: 1;
				font-weight: 400;
				text-align: center;
				font-size: 32rpx;
				color: #A6A5AF;
			}

			.active {
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #A68A64;
			}
		}
	}

	.main_from {
		width: 690rpx;
		height: 350rpx;
		background: #F2F2F2;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 0 auto;
		margin-bottom: 30rpx;

		.main_from_top {
			margin: 0 auto;
			width: 630rpx;
			height: 220rpx;
			border-bottom: 2rpx solid #CFC4B7;
			position: relative;

			>image {
				width: 154rpx;
				height: 154rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-top: 30rpx;
			}

			.main_from_top_one {
				width: 420rpx;
				position: absolute;
				top: 36rpx;
				left: 192rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.name {
					width: 220rpx;
					height: 52rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #333333;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					/* 显示省略号 */
				}

				.time {
					line-height: 52rpx;
					height: 52rpx;
					font-size: 26rpx;
					color: #A68A64;
				}

				.main_from_top_one_text {
					width: 130rpx;
					text-align: right;
					font-size: 26rpx;
					color: #A68A64;
					line-height: 26rpx;
					margin-left: 60rpx;
				}
			}

			.main_from_top_two {
				width: 420rpx;
				position: absolute;
				top: 86rpx;
				left: 192rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.text {
					width: 280rpx;
					height: 52rpx;
					line-height: 52rpx;

					font-weight: 400;
					font-size: 24rpx;
					color: #A68A64;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					/* 显示省略号 */
				}

				.num {

					font-size: 30rpx;
					color: #A7A4AD;
				}
			}

			.main_from_top_three {
				width: 420rpx;
				position: absolute;
				top: 146rpx;
				left: 192rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.tag_wrap {
					width: 300rpx;

					font-weight: 400;
					font-size: 24rpx;
					color: #A68A64;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					display: flex;

					/* 显示省略号 */
					.tag {
						width: 64rpx;
						height: 36rpx;
						background: linear-gradient(274deg, #0014FF 0%, #8020EF 50%, #FF2CDF 100%);
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						font-size: 22rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 36rpx;
					}

					.tag_num {
						width: 150rpx;
						height: 36rpx;
						background: #2B2951;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						text-align: center;
						line-height: 36rpx;
						font-size: 24rpx;
						color: #FFFFFF;
					}
				}

				.price {
					display: flex;
					align-items: center;

					.money1 {
						width: 28rpx;
						height: 28rpx;
						margin-right: 6rpx;
					}
					.money2 {
						width: 38rpx;
						height: 28rpx;
						margin-right: 6rpx;
					}
					.money3 {
						width: 36rpx;
						height: 36rpx;
						margin-right: 6rpx;
					}

					font-size: 32rpx;
					color: #A68A64;
				}
			}


			.tip {
				position: absolute;
				top: 74rpx;
				right: 0rpx;
				font-size: 36rpx;
				color: #FF2CDF;
			}
		}

		.main_from_bottom {
			width: 630rpx;
			height: 100rpx;
			margin: 0 auto;
			margin-top: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.main_from_bottom_text {
				width: 104rpx;
				height: 52rpx;
				font-size: 26rpx;
				color: #A6A5AF;
				line-height: 52rpx;
			}

			.btn_canel {
				width: 152rpx;
				height: 52rpx;
				border-radius: 536rpx 536rpx 536rpx 536rpx;
				border: 2rpx solid #A6A5AF;
				font-weight: 400;
				font-size: 26rpx;
				color: #A6A5AF;
				line-height: 52rpx;
				text-align: center;
				margin-left: 226rpx;
			}
			.btn_canel_s{
				width: 152rpx;
				height: 52rpx;
				// border-radius: 536rpx 536rpx 536rpx 536rpx;
				// border: 2rpx solid #A6A5AF;
				font-weight: 400;
				font-size: 26rpx;
				color: #A6A5AF;
				line-height: 52rpx;
				text-align: center;
				margin-left: 226rpx;
			}

			.btn {
				width: 122rpx;
				height: 52rpx;
				border-radius: 536rpx 536rpx 536rpx 536rpx;
				border: 2rpx solid #A68A64;
				font-weight: 400;
				font-size: 26rpx;
				color: #A68A64;
				line-height: 52rpx;
				text-align: center;
			}
		}
	}

	.prompt {
		width: 600rpx;
		min-height: 400rpx;
		background: #E0DDDA;
		margin: 0 auto;
		border-radius: 20rpx;
		color: #333;
		padding-top: 30rpx;
	}

	.prompt>text {
		margin-top: 40rpx;
	}

	.prompt_tit {
		margin: 0 30rpx;
		font-size: 34rpx;
		color: #333;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.prompt_ntm {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		width: 414rpx;
		height: 72rpx;
		line-height: 72rpx;
		background: linear-gradient( 90deg, #AB8E68 0%, #D7BA93 100%);
		border-radius: 28rpx;
		margin-top: 80rpx;
		color: #ffffff;
	}
</style>